package cn.uyunsky.platform.config.bean.combobox;

import java.io.IOException;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import cn.uyunsky.platform.config.ConfigBeanInterface;
import cn.uyunsky.platform.jaxb.XmlConvert;
import cn.uyunsky.platform.jaxb.XmlConvertImpl;

@XmlRootElement(name = "comboboxs")
@XmlAccessorType(XmlAccessType.FIELD)
public class ComboboxsBean implements ConfigBeanInterface {

	@XmlElement(name = "combobox")
	private List<Combobox> combobox;

	public List<Combobox> getCombobox() {
		return combobox;
	}

	public void setCombobox(List<Combobox> combobox) {
		this.combobox = combobox;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("ComboboxsBean [combobox=");
		builder.append(combobox);
		builder.append("]");
		return builder.toString();
	}

	public static void main(String[] args) {
		XmlConvert convert = new XmlConvertImpl();
		Resource res = new ClassPathResource("combox/combox-pl.xml");

		try {
			ComboboxsBean o = convert.unpack(ComboboxsBean.class, res.getInputStream());
			for (Combobox c : o.getCombobox()) {
				if (c.getEntry() != null) {
					System.out.println(c);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
